package com.ztgf.commodity.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.commodity.models.service.ICommodityParamValueService;
import com.ztgf.commodity.models.bo.CommodityParamValueBO;
import com.ztgf.commodity.models.dto.CommodityParamValueDTO;

/**
 * 商品参数值表控制器
 *
 * @author chenyu.wang
 * @Date 2020-06-15 10:13:11
 */

@RestController
@RequestMapping("/api/commodityParamValue")
@Slf4j
@Api(value = "CommodityParamValueApiController", tags = "商品参数值表Api接口")
public class CommodityParamValueApiController {

    @DubboReference
    private ICommodityParamValueService commodityParamValueService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找", notes = "根据id查找")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    public Result<CommodityParamValueDTO> get(@RequestParam("id") Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }

        CommodityParamValueDTO dto = commodityParamValueService.selectById(id);

        return new Result<>(dto);
    }

    @PostMapping("/queryPageList")
    @ApiOperation(value = "商品参数值表列表", notes = "商品参数值表列表")
    public Result<Page<CommodityParamValueDTO>> queryPageList(CommodityParamValueBO bo) {
        Wrapper<CommodityParamValueDTO> wrapper = new EntityWrapper<>();
        Page<CommodityParamValueDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = commodityParamValueService.selectPage(page, wrapper);
        return new Result<>(page);
    }
}
